<?php
namespace Admin\Controller;
use Common\Controller\AdminbaseController;
class WuyefuwuController extends AdminbaseController{
    
    protected $gonggao_model;
    protected $yijian_model;

    function _initialize() {
        parent::_initialize();
        $this->gonggao_model = M("xiaoqugonggao");
        $this->yijian_model = M("yijianbaoxiu");

    }

    public function xqgonggaoadd(){
        $this->display();
    }

    public function xqgonggaolist(){
        $info=$this->gonggao_model->select();
        $this->assign('info', $info);
            $this->display();
    }

    public function xqgonggaoadd_post() {
    	if (IS_POST) {
    		if ($this->gonggao_model->create()) {
    			if ($this->gonggao_model->add()!==false) {
                         
                            $ar=array(
    				'title'=>$_POST['title'],
                                'content'=>$_POST['content'],
                                'istop'=>$_POST['istop']
                                );
                               $this->gonggao_model->add();
    				 $this->success("添加成功！");
    			} else {
    				$this->error("添加失败！");
    			}
    		} else {
    			$this->error($this->gonggao_model->getError());
    		}
    	}
    }
    
    function xqgonggaodelete(){
        $id = intval(I("get.id")); 
          $count = $this->gonggao_model->where(array("parentid" => $id))->count();
    
        if ($this->gonggao_model->delete($id)!==false) {
            $this->success("删除成功！");
        } else {
            $this->error("删除失败！");
        }        
    }
    
    function xqgonggaoupdata(){
        $id = intval(I("get.id"));
        $res=$this->gonggao_model->where('id=%d',array($id))->select();
        $this->assign('res', $res);
        $this->display(); 
    }
    function xqgonggao_save(){
       	if (IS_POST) {
    		if ($this->gonggao_model->create()) {
    			if ($this->gonggao_model->save()!==false) {
                            $ar=array(
    				'name'=>$_POST['title'],
                                'content'=>$_POST['content'],
                                'istop'=>$_POST['istop']
                                );
                               $this->gonggao_model->where('id=%d',array($_POST['id']))->save();
    				 $this->success("更新成功！");
    			} else {
    				$this->error("更新失败！");
    			}
    		} else {
    			$this->error($this->gonggao_model->getError());
    		}
    	}
    }
    
    public function yijianadd(){
        $this->display();
    }

    public function yijianlist(){
        $info=$this->yijian_model->select();
        $this->assign('info', $info);
            $this->display();
    }

    public function yijianadd_post() {
    	if (IS_POST) {
    		if ($this->yijian_model->create()) {
    			if ($this->yijian_model->add()!==false) {
                         
                            $ar=array(
    				'title'=>$_POST['title'],
                                'content'=>$_POST['content'],
                                'name'=>$_POST['name'],
                                'time'=>$_POST['time'],
                                'status'=>$_POST['status'],
                                'xiaoqu'=>$_POST['xiaoqu'],
                                'fanghao'=>$_POST['fanghao'],
                                'chulikefu'=>$_POST['chulikefu']
                                );
                               $this->yijian_model->add();
    				 $this->success("添加成功！");
    			} else {
    				$this->error("添加失败！");
    			}
    		} else {
    			$this->error($this->yijian_model->getError());
    		}
    	}
    }
    
    function yijiandelete(){
        $id = intval(I("get.id")); 
          $count = $this->yijian_model->where(array("parentid" => $id))->count();
    
        if ($this->yijian_model->delete($id)!==false) {
            $this->success("删除成功！");
        } else {
            $this->error("删除失败！");
        }
    }
    
    function yijianupdata(){
        $id = intval(I("get.id"));
        $res=$this->yijian_model->where('id=%d',array($id))->select();
        $this->assign('res', $res);
        $this->display();         
    }
    
    function yijian_save(){
       	if (IS_POST) {
    		if ($this->yijian_model->create()) {
    			if ($this->yijian_model->save()!==false) {
                            $ar=array(
    				'name'=>$_POST['title'],
                                'content'=>$_POST['content'],
                                'name'=>$_POST['name'],
                                'time'=>$_POST['time'],
                                'status'=>$_POST['status'],
                                'xiaoqu'=>$_POST['xiaoqu'],
                                'fanghao'=>$_POST['fanghao'],
                                'chulikefu'=>$_POST['chulikefu']
                                );
                               $this->yijian_model->where('id=%d',array($_POST['id']))->save();
    				 $this->success("更新成功！");
    			} else {
    				$this->error("更新失败！");
    			}
    		} else {
    			$this->error($this->yijian_model->getError());
    		}
    	}
    }
    
}